﻿//格式化优先级列
var formatPriority = function (elCell, oRecord, oColumn, sData) {
    var showText;
    if (sData == "1") {
        showText = "<font color='red'>特急</font>";
    } else if (sData == "2") {
        showText = "<font color='green'>紧急</font>";
    } else {
        showText = "普通";
    }
    elCell.innerHTML =  showText ;
}
//格式化流程图列
var formatShow = function (elCell, oRecord, oColumn, sData) {
    var WorkFlowInstanceId = oRecord.getData("WorkFlowInstanceId");
    var workflowId = oRecord.getData("WorkFlowId");
    var taskCaption = oRecord.getData("TaskCaption");
    var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
    var title = '"' + taskCaption + '流程图"';
    elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>流程图</a><br />";
}
//格式化流程图列
var formatClose = function (elCell, oRecord, oColumn, sData) {
    var WorkFlowInstanceId = oRecord.getData("WorkFlowInstanceId");
    var workflowId = oRecord.getData("WorkFlowId");
    var taskCaption = oRecord.getData("TaskCaption");
    var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
    var title = '"' + taskCaption + '作废"';
    if (sData == '4') {
        elCell.innerHTML = "<a  href='javascript:void(0)' onclick='ColseClick(\""+WorkFlowInstanceId+"\");'>作废流程</a>";
    }
    else {
        elCell.innerHTML = "";
    }
}
//作废
function ColseClick(WorkFlowInstanceId) {
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }
    if (confirm("是否作废此流程?")) {
        var SaveUrl = "../../WorkFlow/Workformat.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "";
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText.substring(0, 1);

                    if (str == "1") {
                        alert("数据作废成功");
                        var recordID = mDataTable.getSelectedRows()[0];
                        if (dl.length == 0) {
                            mDataTable.deleteRow(recordID);
                        }
                        else {
                            for (var i = 0; i < dl.length; i++) {
                                mDataTable.deleteRow(dl[i]);
                            }
                        }
                    }
                    else {
                        alert(res.responseText + "\n" + "数据作废失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
 }
var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert("操作成功"); fnReload();
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};

var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};
var transForForm = function (title, url) {
    parent.addTabs(title,url);
    parent.NeedRefreshPage = this;
}
//格式化业务名列
var formatCaption = function (elCell, oRecord, oColumn, sData) {

    var OperatorInstanceId = oRecord.getData("operatorInstanceId");
    var WorkFlowNo = oRecord.getData("WorkFlowNo");
    var WorkTaskInstanceId = oRecord.getData("WorkTaskInstanceId");
    var TaskName = oRecord.getData("TaskCaption");
    var IsDisplay = oRecord.getData("IsDisplay");
    var title = '"' + sData + '"';
    var url = '"' + "../../Crm/BasePages/WorkTaskCtrlPage.aspx?title=" + sData + "&OperatorInstanceId=" + OperatorInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + '"';
    var pOperatedDes = oRecord.getData("pOperatedDes");
    if (TaskName.length > 1 && TaskName.substr(0, 2) == "查看") {
        url = '"' + "../../Crm/BasePages/WorkTaskCtrlPage.aspx?view=check&title=" + sData + "&OperatorInstanceId=" + OperatorInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + '"';
    } else {          
        if (pOperatedDes.substr(pOperatedDes.length - 1, 1) == ',') {
            url = '"' + "../../Crm/BasePages/WorkTaskCtrlPage.aspx?view=unDone&title=" + sData + "&OperatorInstanceId=" + OperatorInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + '"';
        } 
    }
    elCell.innerHTML = "";
    var sum = 0;
    var urls = "../../Images/new4.gif";
    if (IsDisplay != "") {
        var isDplay = "";
        var isnull = "  ";
        isDplay = IsDisplay.split(',');
        for (i = 0; i < isDplay.length; i++) {
            if (isDplay[i] = const_UserName) {
                sum = 1;
                break;
            }
        }
        if (sum == 0) {
            elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "&nbsp;&nbsp;&nbsp;<img src= " + urls + "></a><br />";
        }
        else {
            elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "</a><br />";
        }
    }
    else {
        elCell.innerHTML = "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "&nbsp;&nbsp;&nbsp;<img  src= " + urls + "></a><br />";
    }

}
//格式化提交人
var formatSubmit = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 10) {
        var WorkFlowInstanceId = oRecord.getData("WorkFlowInstanceId");
        var workflowId = oRecord.getData("WorkFlowId");
        var taskCaption = oRecord.getData("TaskCaption");
        var title = '"' + taskCaption + '流程图"';
        var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
        elCell.innerHTML = sData.substring(0, 10) + "..." + "<a href='javascript:transForForm(" + title + "," + url + ")' style='color:red'>详细</a>";
    }
    else {
        elCell.innerHTML = sData;
    }
}
var formatIsDisplay = function (elCell, oRecord, oColumn, sData) {
    var items = const_UserName;
    var WorkFlowInstanceId = oRecord.getData("WorkFlowInstanceId");
    var WorkFlowNo = oRecord.getData("WorkFlowNo");
    elCell.innerHTML = "";
    var sum = 0;
    if (sData != "") {
        var isDplay = "";
        isDplay = sData.split(',');
        for (i = 0; i < isDplay.length; i++) {
            if (isDplay[i] = const_UserName) {
                sum = 1;
                break;
            }
        }
        if (sum == 0) {
            var url = "../../Images/new1.gif";
            elCell.innerHTML = "<a><img src= " + url + "></a><br />";
        }
    }
    else {
        var url = "../../Images/new1.gif";
        elCell.innerHTML = "<a><img src= " + url + "></a><br />";
    }
}
//自动义双击方法
function CustomDbClick() { }